package
        com.zzc.fee.service.impl;

import com.hos.entity.his.OrderBackfee;
import com.hos.entity.his.OrderCharge;
import com.zzc.fee.mapper.OrderBackfeeMapper;
import com.zzc.fee.mapper.OrderChargeMapper;
import com.zzc.fee.service.OrderChargeService;
import com.zzc.fee.vo.OrderChargeVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author：xIAO_ZHOU_TX
 * @date：Created in 2023/12/26 11:54
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class OrderChargeServiceImpl implements OrderChargeService {
    @Resource
    private OrderChargeMapper orderChargeMapper;
    @Resource
    private OrderBackfeeMapper orderBackfeeMapper;
    @Override
    public List<List> queryAllRevenueData(OrderChargeVo orderChargeVo) {

        List<List> list=new ArrayList<>();
        //收入概况
        List<Map<String,Integer>> infoList=new ArrayList<>();
        Map<String,Integer> totalIncomeMap =new HashMap<>(); //总收入
        Map<String,Integer> totalBackMap =new HashMap<>(); //总退费
        //收入渠道
        List<Map<String,Integer>> incomeList=new ArrayList<>();
        Map<String,Integer> payMap =new HashMap<>(); //现金支付
        Map<String,Integer> payAlMap =new HashMap<>(); //支付宝支付
        Map<String,Integer> wecharMap =new HashMap<>(); //微信支付
        Map<String,Integer> backMap =new HashMap<>(); //现金退费
        Map<String,Integer> backAlMap =new HashMap<>(); //支付宝退费
        Map<String,Integer> backwecharMap =new HashMap<>(); //微信退费

        Integer pay = 0;  //支付现金
        Integer payAl = 0; //支付宝支付金额
        Integer wechar= 0;//微信支付金额
        Integer totalIncome = 0;//总收入金额
        List<OrderCharge> orderCharges = orderChargeMapper.queryAllRevenueData(orderChargeVo.getDateRange());
        for (OrderCharge item: orderCharges) {
            if(item.getPayType().equals("0")){
                pay+= item.getPayTotalPrice();
            }
            if(item.getPayType().equals("1")){
                payAl +=item.getPayTotalPrice();
            }
            if(item.getPayType().equals("2")){
                wechar +=item.getPayTotalPrice();
            }
        }totalIncome  = pay+payAl+wechar;
        payMap.put("pay",pay);
        payAlMap.put("payAl",payAl);
        wecharMap.put("wechar",wechar);
        totalIncomeMap.put("totalIncome",totalIncome);
        incomeList.add(payMap);
        incomeList.add(payAlMap);
        incomeList.add(wecharMap);
        infoList.add(totalIncomeMap);


        Integer back = 0; //退费现金
        Integer backAl = 0; //支付宝退费金额
        Integer backwechar= 0; //微信退费金额
        Integer totalBack=0; //总退费金额
        List<OrderBackfee> orderBackfees = orderBackfeeMapper.queryAllBackSale(orderChargeVo.getDateRange());
        for (OrderBackfee item: orderBackfees) {
            if(item.getBackType().equals("0")){
                back+= item.getBackTotalPrice();
            }
            if(item.getBackType().equals("1")){
                backAl +=item.getBackTotalPrice();
            }
            if(item.getBackType().equals("2")){
                backwechar +=item.getBackTotalPrice();
            }
        }
        totalBack = back+backAl+backwechar;
        backMap.put("back",back);
        backAlMap.put("backAl",backAl);
        backwecharMap.put("backwechar",backwechar);
        totalBackMap.put("totalBack",totalBack);

        incomeList.add(backMap);
        incomeList.add(backAlMap);
        incomeList.add(backwecharMap);
        infoList.add(totalBackMap);

        list.add(infoList);
        list.add(incomeList);
        return  list;
    }


}